/*
 * Bit.h
 *
 * Created: 22.03.2013 13:32:28
 *  Author: Stefan
 */ 


#ifndef BIT_H
#define BIT_H 1

#include <stdbool.h>


// set bit
/*static*/ inline void setBit(volatile uint8_t *target, uint8_t bit) __attribute__((always_inline));
/*static*/ inline void setBit(volatile uint8_t *target, uint8_t bit){
	*target |= (1<<bit);
};

// set clear
/*static*/ inline void clearBit(volatile uint8_t *target, uint8_t bit) __attribute__((always_inline));
/*static*/ inline void clearBit(volatile uint8_t *target, uint8_t bit){
	*target &= ~(1<<bit);
};

// bit toogle
/*static*/ inline void toggleBit(volatile uint8_t *target, uint8_t bit) __attribute__((always_inline));
/*static*/ inline void toggleBit(volatile uint8_t *target, uint8_t bit){
	*target ^= (1<<bit);
};

// set bit by boolean
/*static*/ inline void setBitBool(volatile uint8_t *target, uint8_t bit, bool enable) __attribute__((always_inline));
/*static*/ inline void setBitBool(volatile uint8_t *target, uint8_t bit, bool enable){
	if (enable){
		setBit(target, bit);
	}else{
		clearBit(target, bit);
	}
};

// get bit
/*static*/ inline bool getBit8(volatile uint8_t target, uint8_t bit) __attribute__((always_inline));
/*static*/ inline bool getBit8(volatile uint8_t target, uint8_t bit){
	if (target & (1<<bit)) {
		return true;
	} else {
		return false;
	}
};
/*static*/ inline bool getBit16(volatile uint16_t target, uint8_t bit) __attribute__((always_inline));
/*static*/ inline bool getBit16(volatile uint16_t target, uint8_t bit){
	if (target & (1<<bit)) {
		return true;
	} else {
		return false;
	}
};



#endif /* BIT_H_ */